<?php

namespace App\Http\Controllers\Company;

use App\Facades\Style;
use App\Http\Controllers\Company\CommonController;
use App\Models\Common\CollArea;
use App\Models\Common\CollOption;
use App\Models\Personal\ResumeSend;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class BuyController extends CommonController
{

    /**
     * 已购买简历
     * @param Request $request
     * @return mixed
     */
    public function index(Request $request){
        $user = auth()->guard('company')->user();
        //获取面试通知记录
        $relist = DB::table('buy_resume as log')
            ->join('resume as t1', 'log.resume_id', '=', 't1.id')
            ->select(
                'log.id','log.updated_at','t1.name','t1.sex','t1.birthday',
                't1.education','t1.homeaddress','t1.intentionjobs','t1.jobarea1','t1.jobarea2','t1.jobarea3','t1.jobarea4','t1.jobarea5','log.resume_id'
            )
            ->where('log.company_uid',$user->uid)
            ->where(function ($query) use ($request) {
                if(strlen($request->keyWord)>0){
                    $query->where('t1.intentionjobs', 'like', '%'.$request->keyWord.'%')->orWhere('t1.name','like','%'.$request->keyWord.'%');
                }
            })
            ->orderBy('log.updated_at','DESC')
            ->paginate(20);
        //print_r($queries );
        //dd($relist);

        foreach($relist as $v){
            switch($v->sex){
                case "1":
                    $v->cnsex='男';
                    break;
                case "2":
                    $v->cnsex='女';
                    break;
                default:
                    $v->cnsex='';
            }
            $v->education=CollOption::getOptionName($v->education,'education');
            $v->homeaddress=CollArea::getAreaName($v->homeaddress);
            $v->birthday=birthday($v->birthday);
            $v->jobarea=$v->jobarea1?CollArea::getAreaName($v->jobarea1):'';
            $v->jobarea.=$v->jobarea2?';'.CollArea::getAreaName($v->jobarea2):'';
            $v->jobarea.=$v->jobarea3?';'.CollArea::getAreaName($v->jobarea3):'';
            $v->jobarea.=$v->jobarea4?';'.CollArea::getAreaName($v->jobarea4):'';
            $v->jobarea.=$v->jobarea5?';'.CollArea::getAreaName($v->jobarea5):'';
        }

        return Style::view('company.buyIndex',compact('relist'));
    }
}